package com.edu.exam.entity.curriculum.academic;

import com.edu.exam.entity.curriculum.academic.enums.OfferingStatus;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 专业层次开设关系实体类
 * 所属模块：F-02 专业培养层次管理模块
 * 对应数据库表：major_level_offerings
 *
 * 根据F-02专业培养层次管理模块设计文档实现
 * 管理专业与培养层次的开设关系，包括生效日期、状态等。
 * 支持专业层次开设关系的创建、查询和更新。
 *
 * @author System
 * @version 2.0.0
 */
@Entity
@Table(name = "major_level_offerings",
       uniqueConstraints = @UniqueConstraint(columnNames = {"major_id", "education_level_id"},
                                                name = "uk_major_education_level"))
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MajorLevelOffering {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @NotNull(message = "专业不能为空")
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "major_id", referencedColumnName = "id", nullable = false, foreignKey = @ForeignKey(name = "fk_major_level_offering_major"))
    private Major major;

    @NotNull(message = "培养层次不能为空")
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "education_level_id", referencedColumnName = "id", nullable = false, foreignKey = @ForeignKey(name = "fk_major_level_offering_education_level"))
    private EducationLevel educationLevel;

    @NotNull(message = "生效日期不能为空")
    @Column(name = "effective_date", nullable = false)
    private LocalDate effectiveDate;

    @Column(name = "expiry_date")
    private LocalDate expiryDate;

    @NotNull(message = "开设关系状态不能为空")
    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 20)
    private OfferingStatus status;

    @Column(name = "offering_description", columnDefinition = "TEXT")
    private String offeringDescription;

    @Size(max = 50, message = "创建人长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    @CreatedDate
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;

    @LastModifiedDate
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

}
